#!/bin/bash
# TensorRT推理启动脚本

echo "🚀 启动TensorRT推理系统"

# 进入项目目录
cd /home/wuyin/ros_ws/src/yolov5-ukf-imm

# 激活虚拟环境
source ../../.venv/bin/activate

# 加载TensorRT环境 (如果存在)
if [ -f "../../.venv/bin/setup_tensorrt_env" ]; then
    source ../../.venv/bin/setup_tensorrt_env
fi

# 检查模型文件
if [ ! -f "weights/yolo11n.engine" ]; then
    echo "❌ TensorRT引擎文件不存在: weights/yolo11n.engine"
    echo "💡 尝试使用现有的高级检测系统..."
    
    # 尝试运行高级检测系统
    if [ -f "camera_detect_advanced.py" ]; then
        echo "📷 启动高级摄像头检测系统..."
        python3 camera_detect_advanced.py --weights weights/yolo11n.engine --camera 0
    else
        echo "❌ 无可用的推理脚本"
        exit 1
    fi
else
    echo "✅ 找到TensorRT引擎文件"
    echo "📷 启动摄像头推理..."
    
    # 首先尝试简化的推理脚本
    if [ -f "simple_tensorrt_inference.py" ]; then
        python3 simple_tensorrt_inference.py --engine weights/yolo11n.engine --camera 0 --show-fps
    else
        # 回退到高级检测系统
        python3 camera_detect_advanced.py --weights weights/yolo11n.engine --camera 0
    fi
fi

echo "🎉 推理系统已退出"